﻿namespace Sunny.UI.Demo.Forms
{
    public partial class FEditForm : UIEditForm
    {
        public FEditForm()
        {
            InitializeComponent();
        }

        protected override bool CheckData()
        {
            return CheckEmpty(tbRasterName, "请输入传感器名称")
                   && CheckEmpty(cbRasterType, "请输入传感器类型")
                   && CheckRange(tbChannelIndex, 0, 15, "请输入通道号，范围0~15")
                   && CheckRange(tbRasterIndex, 0, 29, "请输入传感器号，范围0~29")
                   && CheckRange(tbWaveCount, 0, 29, "请输入波长数量，范围1~4")
                   && CheckEmpty(tbExpression, "请输入传感器物理值计算表达式");
        }

        private EditRaster editRaster;

        public EditRaster EditRaster
        {
            get
            {
                if (editRaster == null)
                {
                    editRaster = new EditRaster();
                }
                editRaster.RasterID = tbRasterID.IntValue;
                editRaster.RasterName = tbRasterName.Text;
                editRaster.RasterType = cbRasterType.SelectedIndex;
                editRaster.ChannelIndex = tbChannelIndex.IntValue;
                editRaster.RasterIndex = tbRasterIndex.IntValue;
                editRaster.WaveCount = tbWaveCount.IntValue;
                editRaster.RasterDes = tbRasterDes.Text;
                editRaster.Expression = tbExpression.Text;
                return editRaster;
            }

            set
            {
                editRaster = value;
                tbRasterID.IntValue = value.RasterID;
                tbRasterName.Text = value.RasterName;
                cbRasterType.SelectedIndex = cbRasterType.Items.IndexOf(value.RasterType);
                tbChannelIndex.IntValue = value.ChannelIndex;
                tbRasterIndex.IntValue = value.RasterIndex;
                tbWaveCount.IntValue = value.WaveCount;
                tbRasterDes.Text = value.RasterDes;
                tbExpression.Text = value.Expression;
            }
        }
    }
}


public class EditRaster
{
    public int RasterID { get; set; }

    public string RasterName { get; set; }

    public int RasterType { get; set; }

    public int ChannelIndex { get; set; }

    public int RasterIndex { get; set; }

    public int WaveCount { get; set; }

    public string RasterDes { get; set; }

    public string Expression { get; set; }

    public override string ToString()
    {
        return RasterName + ", " + RasterType + ", " + ChannelIndex + ", " + RasterIndex;
    }
}